Skip to content

[cxx-interop] Add documentation about inferring SWIFT_SHARED_REFERENCE in c++ inheritance #1078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

Conversation

fahadnayyar
Copy link

Adding a sentence in the documentation thatthe foreign-reference annotations are now propagated to inherited C++ types

@fahadnayyar fahadnayyar marked this pull request as ready for review June 10, 2025 22:01
@Xazax-hun
Copy link
Contributor

cc @egorzhdan

@fahadnayyar
Copy link
Author

CC: @j-hui
if you can also please take a look!

@fahadnayyar
Copy link
Author

CC: @ravikandhadai

@fahadnayyar
Copy link
Author

This patch needs 2 important things to be included:

  • behaviour in case of multiple inheritance.
  • Clarification about immortal references.


When a C++ type inherits from a `SWIFT_SHARED_REFERENCE` base type, the Swift compiler automatically infers `SWIFT_SHARED_REFERENCE` annotation for the derived type.
The derived type also gets imported as a reference type, and uses the same `retain` and `release` functions as its base class.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@j-hui I changed some text based on your suggestions but added my flavor as well. How does it look now?

@@ -1255,6 +1255,17 @@ object.doSomething()
// `object` will be released here.
```

### Inference of Shared Reference behaviour in Derived Types
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: ### -> ####

@fahadnayyar
Copy link
Author

including this in PR-1106

@fahadnayyar fahadnayyar closed this Jul 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants